import { ref, onActivated } from 'vue';

/**
 * keepAlive页面回到初始页面时刷新操作
 * @param refresh 刷新函数
 */
export const useKeepAliveRefresh = (refresh: () => void) => {
  const isFirstEnter = ref(true);
  onActivated(() => {
    console.log('onActivated', isFirstEnter.value);
    if (isFirstEnter.value === true) {
      isFirstEnter.value = false;
    } else {
      refresh && refresh();
    }
  });
};
